
package com.insigma.business.qrcode.job._bff.impl;


import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.insigma.business.qrcode.common.converter.JobRecruitPositionTypeProviderConverter;
import com.insigma.business.qrcode.common.dto.*;
import com.insigma.business.qrcode.common.dto.MessageMaterialTypeEnum;
import com.insigma.business.qrcode.common.dto.MessageTypeEnum;
import com.insigma.business.qrcode.common._provider.BuriedPointProvider;
import com.insigma.business.qrcode.common._consumer.CommonAdminAreaConsumer;
import com.insigma.business.qrcode.common.template.BasePagingResponse;
import com.insigma.business.qrcode.common.template.MemCacheManager;
import com.insigma.business.qrcode.common.template.area.BaseProviderImpl;
import com.insigma.business.qrcode.common.template.area.ScenarioCodeEnum;
import com.insigma.business.qrcode.common.template.area.ServiceCallback;
import com.insigma.business.qrcode.common.util.*;
import com.insigma.business.qrcode.common.vo.*;
import com.insigma.business.qrcode.job.dto.request.JobFavoriteInsertRequest;
import com.insigma.business.qrcode.job.dto.request.JobRecruitPositionInsertRequest;
import com.insigma.business.qrcode.job.dto.request.JobRecruitPositionSearchRequest;
import com.insigma.business.qrcode.job.dto.request.JobRecruitPositionUpdateRequest;
import com.insigma.business.qrcode.job.dto.search.JobRecruitPositionTypeBSearcher;
import com.insigma.business.qrcode.job.entity.JobRecruitPositionTypeDO;
import com.insigma.business.qrcode.job.service.JobRecruitPositionTypeService;
import com.insigma.business.qrcode.soldier.dto.*;
import com.insigma.business.qrcode.soldier.request.BaseGetRequest;
import com.insigma.business.qrcode.soldier.request.SoldierMessageInfoInsertRequest;
import com.insigma.business.qrcode.soldier.request.SoldierUnemploymentRegistrationInfoSearchRequest;
import com.insigma.business.qrcode.soldier._consumer.CompanyConsumer;
import com.insigma.business.qrcode.soldier._consumer.SoldierMessageInfoConsumer;
import com.insigma.business.qrcode.soldier.request.SoldierUnemploymentRegistrationInfoUpdateRequest;
import com.insigma.business.qrcode.soldier.util.ThreadPoolManager;
import com.insigma.business.qrcode.job.consumer.*;
import com.insigma.business.qrcode.job.dto.*;
import com.insigma.business.qrcode.job._bff.JobRecruitPositionBFFProvider;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;


@Slf4j
@Service
//@Component("jobRecruitPositionBffProvider")
public class JobRecruitPositionBFFProviderImpl extends BaseProviderImpl implements JobRecruitPositionBFFProvider {

    @Autowired
    private JobRecruitPositionConsumer jobRecruitPositionConsumer;

    @Autowired
    private SoldierMessageInfoConsumer soldierMessageInfoConsumer;

    @Autowired
    private JobRecruitPositionTypeConsumer jobRecruitPositionTypeConsumer;

    @Autowired
    private SoldierUnemploymentRegistrationInfoConsumer soldierUnemploymentRegistrationInfoConsumer;

    @Autowired
    private SoldierBasicInfoConsumer soldierBasicInfoConsumer;

    @Autowired
    private CandidateResumeConsumer candidateResumeConsumer;

    @Autowired
    private CompanyConsumer companyConsumer;

    @Autowired
    private CommonAdminAreaConsumer commonAdminAreaConsumer;

    @Autowired
    private BuriedPointProvider buriedPointProvider;

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private JobRecruitPositionTypeService jobRecruitPositionTypeService;


    @Override
    public BaseResponse<Boolean> testToRecommendPosition(JobRecruitPositionUpdateRequest request) {
        recommendPosition(request.getIdList());
        return ResponseUtils.buildSuccessResponse(true);
    }

    @Override
    public BasePagingResponse<List<JobRecruitPositionDTO>> searchUserRecruitPosition(JobRecruitPositionSearchRequest searchRequest) {
        BizCheckUtil.checkNotNull(searchRequest, "查询分页JobRecruitPosition的请求参数不能为空");


        if (Strings.isBlank(searchRequest.getMode()) && Strings.isBlank(searchRequest.getFairId())) {
            searchRequest.setMode(FairModeEnum.OFFLINE.name());
        }
        SessionSoldier sessionSoldier = RpcContextUtil.getSessionSoldier();
        if (sessionSoldier != null) {
            searchRequest.setSoldierId(sessionSoldier.getUserId());
        }
        ThreadPoolManager.getInstance().submit(new Runnable() {
            @Override
            public void run() {
                if (sessionSoldier != null) {
                    SoldierUnemploymentRegistrationInfoUpdateRequest registrationInfoUpdateRequest = new SoldierUnemploymentRegistrationInfoUpdateRequest();
                    registrationInfoUpdateRequest.setSoldierId(sessionSoldier.getUserId());
                    soldierUnemploymentRegistrationInfoConsumer.setAsRecommend(registrationInfoUpdateRequest);
                }
            }
        });

        BasePagingResponse<List<JobRecruitPositionDTO>> listBasePagingResponse = jobRecruitPositionConsumer.searchJobRecruitPosition(searchRequest);
        List<JobRecruitPositionDTO> dtos = listBasePagingResponse.getDto();
        addCityAndCompanyInfoToDtos(dtos);

        return listBasePagingResponse;
    }


    private void recommendPosition(List<String> idList) {
        ThreadPoolManager.getInstance().submit(new Runnable() {
            @Override
            public void run() {

                try {
                    log.info("职位推荐");
                    List<SoldierUnemploymentRegistrationInfoDTO> unemploymentSoldierList = soldierUnemploymentRegistrationInfoConsumer.listAllUnemploymentSolider(new SoldierUnemploymentRegistrationInfoSearchRequest()).getDto();
                    if (CollectionUtils.isEmpty(unemploymentSoldierList)) {
                        return;
                    }

                    for (String id : idList) {
                        JobRecruitPositionDTO dto = getOrgRecruitPosition(new BaseApiGetRequest(id)).getDto();
                        if (dto == null) {
                            return;
                        }

                        String typeName = dto.getTypeName();
                        List<String> positionTypeIds = JSONArray.parseArray(typeName, String.class);
                        List<String> positionTypeNames = Lists.newArrayList();
                        for (String s : positionTypeIds) {
                            JobRecruitPositionTypeDTO positionTypeDTO = jobRecruitPositionTypeConsumer.getJobRecruitPositionTypeByCode(s).getDto();
                            if (positionTypeDTO != null) {
                                positionTypeNames.add(positionTypeDTO.getName());
                            }
                        }
                        log.info("职位推荐：positionTypeNames: {}", positionTypeNames);
                        List<SoldierUnemploymentRegistrationInfoDTO> needRecommendSoldiers = Lists.newArrayList();
                        for (SoldierUnemploymentRegistrationInfoDTO unemploymentSoldier : unemploymentSoldierList) {
                            try {
                                String idCardNo = unemploymentSoldier.getIdCardNo();
                                SoldierBasicInfoDTO basicInfo = soldierBasicInfoConsumer.getSoldierBasicInfo(idCardNo).getDto();
                                if (basicInfo == null || Strings.isBlank(basicInfo.getSoldierId())) {
                                    continue;
                                }

                                JobCandidateResumeDTO resumeDTO = candidateResumeConsumer.getMyResume(basicInfo.getSoldierId()).getDto();
                                if (resumeDTO == null) {
                                    continue;
                                }

                                String expectedInfo = resumeDTO.getExpectedInfo();
                                if (Strings.isNotBlank(expectedInfo)) {
                                    List<ExpectedInfoRequest> expectedInfoRequests = JSONArray.parseArray(expectedInfo, ExpectedInfoRequest.class);
                                    for (ExpectedInfoRequest expectedInfoRequest : expectedInfoRequests) {
                                        String expectedPositionTypeIds = expectedInfoRequest.getExpectedPositionTypeId();
                                        if (Strings.isNotBlank(expectedPositionTypeIds)) {
                                            List<String> expectPositionTypeIds = null;
                                            if (expectedPositionTypeIds.contains("[")) {
                                                expectPositionTypeIds = JSONArray.parseArray(expectedPositionTypeIds, String.class);
                                            } else {
                                                expectPositionTypeIds = Lists.newArrayList(expectedPositionTypeIds.trim().split(","));
                                            }
                                            Sets.SetView<String> intersection = Sets.intersection(Sets.newHashSet(expectPositionTypeIds), Sets.newHashSet(positionTypeIds));
                                            if (intersection.size() > 0) {
                                                needRecommendSoldiers.add(unemploymentSoldier);
                                                log.info("职位推荐：unemploymentSoldier:{}", unemploymentSoldier);
                                                break;
                                            }
                                        }
                                    }
                                }
                            } catch (Exception e) {
                                log.error("推荐失败：{},{}", unemploymentSoldier.getIdCardNo(), e);
                            }
                        }

                        for (SoldierUnemploymentRegistrationInfoDTO needRecommendSoldier : needRecommendSoldiers) {
                            soldierMessageInfoConsumer.insertSoldierMessageInfo(buildJobRecommendMessage(needRecommendSoldier, dto));
                        }
                    }
                } catch (Exception e) {
                    log.error("推荐失败：{}", e);
                }
            }
        });
    }

    private SoldierMessageInfoInsertRequest buildJobRecommendMessage(SoldierUnemploymentRegistrationInfoDTO needRecommendSoldier, JobRecruitPositionDTO jobRecruitPositionDTO) {
        SoldierMessageInfoInsertRequest request = new SoldierMessageInfoInsertRequest();
        request.setSoldierId(needRecommendSoldier.getSoldierId());
        request.setRealName(needRecommendSoldier.getRealName());
        request.setIdCardNo(needRecommendSoldier.getIdCardNo());
        request.setBizType(MessageTypeEnum.UNEMPLOYMENT.name());
        request.setBizId(jobRecruitPositionDTO.getId());
        request.setRead(false);
        request.setRemind(false);
        request.setPublished(true);
        request.setValidPeriod(false);
        request.setMaterialType(MessageMaterialTypeEnum.RTF.name());
        request.setTitle(jobRecruitPositionDTO.getName());
        request.setIntroduction("推荐公司:" + jobRecruitPositionDTO.getOrgName() + "," + "推荐职位：" + jobRecruitPositionDTO.getName());

        String template = "<a href=\"https://shh.zhlb.tyjrswj.hangzhou.gov.cn/pages/user/company/jobList/detail/index?id=%s\">\n" +
                "      <view style=\" box-sizing: border-box;width: 100%%;background-color: #ffffff;position: relative;\">\n" +
                "        <view style=\"position: absolute;background-color: #FF3A30;color: #FFFFFF;width: 40rpx;height: 40rpx;display: flex;align-items: center;justify-content: center;border-radius: 50%%;top: -20rpx;\">荐\n" +
                "        </view>\n" +
                "        <view style=\" flex: 3;display: flex;flex-direction: column;border: 1rpx solid #E5E5EA;padding: 10rpx;border-radius: 8rpx;\">\n" +
                "          <view style=\"display: flex;justify-content: space-between;margin-bottom: 10rpx;\">\n" +
                "            <view style=\"flex: 1;font-size: 34rpx;font-weight: 600;color: #333333;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;width: 500rpx;\">%s</view>\n" +
                "            <view style=\"width: 200rpx;text-align: right;\">\n" +
                "              <text style=\"color: #FFA940;font-weight: 600;font-size: 28rpx;width: 200rpx;\">%s</text></text>\n" +
                "            </view>\n" +
                "          </view>\n" +
                "          <view style=\"display: flex;margin-bottom: 10rpx;\">\n" +
                "            <view style=\"background-color: #F8F8F8;margin-right: 20rpx;padding: 0 10rpx;border-radius: 5rpx;\">\n" +
                "              <text style=\"font-size: 24rpx;color: #E29836;background-color:#FDF5E9;\">%s</text>\n" +
                "            </view>\n" +
                "            <view style=\"background-color: #F8F8F8;padding: 0 10rpx;border-radius: 5rpx;\">\n" +
                "              <text style=\"font-size: 24rpx;color: #7AC756;background-color: #EEF8E8;\">%s</text>\n" +
                "            </view>\n" +
                "          </view>\n" +
                "          <view style=\"margin-bottom: 10rpx;\">\n" +
                "            <view style=\"font-size: 28rpx;color: #666666;display: flex;justify-content: space-between;\">\n" +
                "              <view style=\"overflow: hidden;text-overflow:ellipsis;white-space: nowrap;flex: 1;width: 500rpx;\">\n" +
                "                <text>%s</text>\n" +
                "              </view>\n" +
                "              <view style=\"width: 200rpx;text-align: right;\">\n" +
                "                %s\n" +
                "              </view>\n" +
                "            </view>\n" +
                "          </view>\n" +
                "          <view style=\"display: flex;justify-content: space-between;font-size: 24rpx;height: 50rpx;\">\n" +
                "            <text style=\"color: #a0a0a0;display: flex;align-items: center;\">%s</text>\n" +
                "            <text style=\"color: #a0a0a0;display: flex;align-items: center;\">\n" +
                "              %s <text style=\"padding: 0 0rpx;\"></text>\n" +
                "            </text>\n" +
                "          </view>\n" +
                "        </view>\n" +
                "      </view>\n" +
                "    </a>";
        String money = buildMoneyCN(jobRecruitPositionDTO.getSalaryRangeMin(), jobRecruitPositionDTO.getSalaryRangeMax());
        String education = buildEducationCN(jobRecruitPositionDTO.getEducationRequirementMin());
        String exp = buildExperienceCN(jobRecruitPositionDTO.getExperienceRequirement());
        String unitSize = buildCompanyUnitSize(jobRecruitPositionDTO.getCompany().getUnitSize());
        String label = buildLabelCN(jobRecruitPositionDTO.getLabel());

        request.setDetail(String.format(template, jobRecruitPositionDTO.getId(), jobRecruitPositionDTO.getName(), money, education, exp, jobRecruitPositionDTO.getOrgName(), unitSize, label, jobRecruitPositionDTO.getCity()));
        return request;
    }
    private String buildLabelCN(String label) {
        label = label.replace("[", "");
        label = label.replace("]", "");
        return label;
    }

    private String buildCompanyUnitSize(String unitSize) {
        if (!unitSize.contains("[")) {
            return unitSize;
        }
        if (unitSize.contains("∞")) {
            unitSize = unitSize.replace("∞", "0");
            List<Integer> integers = JSONArray.parseArray(unitSize, Integer.class);
            return integers.get(0) + "人以上";
        }

        List<Integer> integers = JSONArray.parseArray(unitSize, Integer.class);
        return integers.get(0) + " ~ " + integers.get(1) + "人";
    }
    private String buildExperienceCN(String experienceRequirement) {
        if (Strings.isBlank(experienceRequirement)) {
            return "不限";
        }
        if (experienceRequirement.contains("∞")) {
            return "不限";
        }

        List<Integer> integers = JSONArray.parseArray(experienceRequirement, Integer.class);
        return integers.get(0) + " - " + integers.get(1) + "年";
    }
    private String buildMoneyCN(Integer salaryRangeMin, Integer salaryRangeMax) {
        if (salaryRangeMin == -1) {
            return "不限";
        }
        return salaryRangeMin / 1000 + "k - " + salaryRangeMax / 1000 + "k";
    }
    private String buildEducationCN(String educationRequirementMin) {
        if (educationRequirementMin.equals("0")) {
            return "初中";
        }
        if (educationRequirementMin.equals("1")) {
            return "高中";
        }
        if (educationRequirementMin.equals("2")) {
            return "中专";
        }
        if (educationRequirementMin.equals("3")) {
            return "大专";
        }
        if (educationRequirementMin.equals("4")) {
            return "本科";
        }
        if (educationRequirementMin.equals("5")) {
            return "研究生";
        }
        if (educationRequirementMin.equals("6")) {
            return "博士";
        }
        return "不限";
    }
    @Override
    public BasePagingResponse<List<JobRecruitPositionDTO>> searchUserRecruitPositionOfZph(JobRecruitPositionSearchRequest searchRequest) {

        BizCheckUtil.checkNotNull(searchRequest, "查询分页JobRecruitPosition的请求参数不能为空");


        if (Strings.isBlank(searchRequest.getMode()) && Strings.isBlank(searchRequest.getFairId())) {
            searchRequest.setMode(FairModeEnum.OFFLINE.name());
        }
        SessionSoldier sessionSoldier = RpcContextUtil.getSessionSoldier();
        if (sessionSoldier != null) {
            searchRequest.setSoldierId(sessionSoldier.getUserId());
        }
        BasePagingResponse<List<JobRecruitPositionDTO>> listBasePagingResponse = jobRecruitPositionConsumer.searchJobRecruitPosition(searchRequest);
        List<JobRecruitPositionDTO> dtos = listBasePagingResponse.getDto();
        addCityAndCompanyInfoToDtos(dtos);

        return listBasePagingResponse;
    }

    @Override
    public BaseResponse<String> insertJobPositionFavorite(JobFavoriteInsertRequest jobFavoriteInsertRequest) {
        return null;
    }

    @Override
    public BasePagingResponse<List<JobRecruitPositionDTO>> searchMyFavoritePosition(JobRecruitPositionSearchRequest orgRecruitPositionSearchRequest) {
        return null;
    }

    @Override
    public BaseResponse<String> insertCompanyRecruitPositionOfFair(JobRecruitPositionInsertRequest orgRecruitPositionInsertRequest) {
        return null;
    }

    @Override
    public BaseResponse<ExcelResultBO> exportCompanyRecruitPosition(JobRecruitPositionSearchRequest orgRecruitPositionSearchRequest) {
        return null;
    }

    @Override
    public BasePagingResponse<List<JobRecruitPositionDTO>> searchJobStats(CommonLedgerStatsRequest request) {
        return null;
    }

    private void addCityAndCompanyInfoToDtos(List<JobRecruitPositionDTO> dtos) {
        if (CollectionUtils.isEmpty(dtos)) {
            return;
        }

        for (JobRecruitPositionDTO dto : dtos) {

            CompanyDTO cachedCompanyInfo = getCachedCompanyInfo(dto.getOrgId());
            if (cachedCompanyInfo != null) {
                dto.setUnitSize(cachedCompanyInfo.getUnitSize());
            }
            Integer applyNum = jobRecruitPositionConsumer.countPositionApply(dto.getId()).getDto();
            dto.setApplyNum(applyNum);


            String typeName = dto.getTypeName();
            if (Strings.isNotBlank(typeName)) {
                try {
                    List<String> itList = JSONArray.parseArray(typeName, String.class);
                    if (!CollectionUtils.isEmpty(itList)) {
                        String s = itList.get(0);
                        String cachedPositionType = getCachedPositionType(s);
                        dto.setTypeNameCN(cachedPositionType);
                    }
                } catch (Exception e) {
                    log.error("json 转换错误", e);
                }
            }


            String adminAreaCode = dto.getWorkCity();
            if (Strings.isBlank(adminAreaCode)) {
                continue;
            }
            String s = AdminAreaCodeUtils.cutAreaCode(AdminAreaCodeUtils.fillAreaCode(adminAreaCode), "3");
            CommonAdminAreaDTO adminAreaById = commonAdminAreaConsumer.getAdminAreaById(AdminAreaCodeUtils.fillAreaCode(s));
            if (adminAreaById != null) {
                dto.setCity(adminAreaById.getValue());
            }
        }
    }
    public String getCachedPositionType(String id) {
        String key = "POSITION_TYPE_CODE:" + id;
        String o = (String) redisUtils.get(key);
        if (o == null) {
            JobRecruitPositionTypeDTO typeDto = jobRecruitPositionTypeConsumer.getJobRecruitPositionTypeByCode(id).getDto();
            if (typeDto != null) {
                o = typeDto.getName();
            } else {
                o = "";
            }
            redisUtils.set(key, o);
        }
        return o;
    }

    @Override
    public BasePagingResponse<List<JobRecruitPositionDTO>> searchOrgRecruitPosition(JobRecruitPositionSearchRequest orgRecruitPositionSearchRequest) {
        return null;
    }

    @Override
    public BasePagingResponse<List<JobRecruitPositionDTO>> searchOrgRecruitPositionForZZD(JobRecruitPositionSearchRequest orgRecruitPositionSearchRequest) {
        return null;
    }

    @Override
    public BasePagingResponse<List<JobRecruitPositionDTO>> searchCompanyRecruitPosition(JobRecruitPositionSearchRequest orgRecruitPositionSearchRequest) {
        return null;
    }

    @Override
    public BasePagingResponse<List<JobRecruitPositionDTO>> searchCompanyRecruitPositionOfFair(JobRecruitPositionSearchRequest orgRecruitPositionSearchRequest) {
        return null;
    }

    @Override
    public BaseResponse<JobRecruitPositionDTO> getOrgRecruitPosition(final BaseApiGetRequest request) {

        final BaseResponse<JobRecruitPositionDTO> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(request, "获取单条JobRecruitPosition的请求参数不能为空");
                BizCheckUtil.checkNotBlank((String) request.getId(), "id不能为空");
            }

            @Override
            public void executeService() {

                SessionSoldier sessionSoldier = RpcContextUtil.getSessionSoldier();
                if (sessionSoldier != null) {
                    request.setSoldierId(sessionSoldier.getUserId());
                }

                final BaseResponse<JobRecruitPositionDTO> jobRecruitPositionResponse = jobRecruitPositionConsumer.getJobRecruitPosition(request);
                JobRecruitPositionDTO dto = jobRecruitPositionResponse.getDto();
                if (dto != null) {
                    String workCity = dto.getWorkCity();
                    if (Strings.isNotBlank(workCity)) {
                        String s = AdminAreaCodeUtils.cutAreaCode(workCity, "3");
                        CommonAdminAreaDTO adminAreaById = commonAdminAreaConsumer.getAdminAreaById(AdminAreaCodeUtils.fillAreaCode(s));
                        dto.setCity(adminAreaById.getValue());
                    }
                }

                BeanUtil.copyProperties(jobRecruitPositionResponse, baseResponse);

                buriedPointProvider.setBuriedPointByWeek(buildBuriedPointRequest(dto));
                buriedPointProvider.setCountPoint(buildBuriedPointRequest(dto));
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.JOB_RECRUIT_POSITION_GET;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<String> insertMyCompanyPosition(JobRecruitPositionInsertRequest orgRecruitPositionInsertRequest) {
        return null;
    }

    @Override
    public BaseResponse<String> insertCompanyRecruitPosition(JobRecruitPositionInsertRequest orgRecruitPositionInsertRequest) {
        return null;
    }

    @Override
    public BaseResponse<Integer> updateOrgRecruitPosition(JobRecruitPositionUpdateRequest orgRecruitPositionUpdateRequest) {
        return null;
    }

    @Override
    public BaseResponse<List<JobRecruitPositionTypeDTO>> getPositionTypeTree() {
        List<JobRecruitPositionTypeDO> allType = jobRecruitPositionTypeService.search(new JobRecruitPositionTypeBSearcher(1, Integer.MAX_VALUE));
        if (CollectionUtils.isEmpty(allType)) {
            return ResponseUtils.buildSuccessResponse(new ArrayList<>());
        }

        Collections.sort(allType, new Comparator<JobRecruitPositionTypeDO>() {
            @Override
            public int compare(JobRecruitPositionTypeDO o1, JobRecruitPositionTypeDO o2) {
                return o1.getId().compareTo(o2.getId());
            }
        });

        Map<String, JobRecruitPositionTypeDTO> map = Maps.newHashMap();
        for (JobRecruitPositionTypeDO jobRecruitPositionTypeDO : allType) {
            JobRecruitPositionTypeDTO jobRecruitPositionTypeDTO = JobRecruitPositionTypeProviderConverter
                    .convertToNewDto(jobRecruitPositionTypeDO);
            String father = jobRecruitPositionTypeDTO.getParentId();
            if (Strings.isNotBlank(father)) {
                JobRecruitPositionTypeDTO fatherDto = map.get(father);
                if (fatherDto.getChildren() == null) {
                    fatherDto.setChildren(new ArrayList<>());
                }
                fatherDto.getChildren().add(jobRecruitPositionTypeDTO);
            }

            map.put(jobRecruitPositionTypeDTO.getId(), jobRecruitPositionTypeDTO);
        }

        List<JobRecruitPositionTypeDTO> result = Lists.newArrayList();
        for (Map.Entry<String, JobRecruitPositionTypeDTO> entry : map.entrySet()) {
            JobRecruitPositionTypeDTO value = entry.getValue();
            if (value.getRoot()) {
                result.add(value);
            }
        }
        return ResponseUtils.buildSuccessResponse(result);
    }

    @Override
    public BaseResponse<List<JobRecruitPositionTypeDTO>> getPositionTypeTreeForZZD() {
        return null;
    }

    @Override
    public BaseResponse<Integer> deleteOrgRecruitPosition(BaseDeleteRequest deleteRequest) {
        return null;
    }

    @Override
    public BaseResponse<Boolean> offShelfRecruitPosition(JobRecruitPositionUpdateRequest request) {
        return null;
    }

    @Override
    public BaseResponse<Boolean> checkRecruitPosition(JobRecruitPositionUpdateRequest request) {
        return null;
    }

    @Override
    public BaseResponse<Boolean> batchCheckRecruitPosition(JobRecruitPositionUpdateRequest request) {
        return null;
    }

    private BuriedPointRequest buildBuriedPointRequest(JobRecruitPositionDTO dto) {
        if (dto == null) {
            return null;
        }

        BuriedPointRequest request = new BuriedPointRequest();
        request.setId(dto.getId());
        request.setName(dto.getName());
        request.setType(BuriedPointTypeEnum.JOB.name());
        return request;
    }

    public CompanyDTO getCachedCompanyInfo(String companyId) {
        try {
            Object o = MemCacheManager.getInstance().get("JOB_COMPANY_INFO_" + companyId, new Callable<Object>() {
                @Override
                public Object call() throws Exception {
                    CompanyDTO dto = companyConsumer.getCompany(new BaseGetRequest(companyId)).getDto();
                    if (dto == null) {
                        return new CompanyDTO();
                    }
                    return dto;
                }
            });
            return (CompanyDTO) o;
        } catch (ExecutionException e) {
            log.error("读取异常：{}", e);
        }
        return null;
    }

}
